package com.actions;
import javax.servlet.http.*;
import javax.swing.JOptionPane;

import java.util.*;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.io.*;
import com.DAO.*;
import com.beans.*;
public class UpdateCategoryAction  extends org.apache.struts.action.Action{

	private final static String SUCCESS = "success";
    
	public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
    	
		System.out.println("In Update Action");
		HttpSession session=request.getSession();
		int id=(Integer)(session.getAttribute("updateid"));
		System.out.println("id............."+id);
		CategoryForm categoryForm=(CategoryForm)form;
		String name=categoryForm.getName();
		System.out.println("name............."+name);
		
		String allowComment=categoryForm.getAllowComment();
		String comment;
		System.out.println("allowComments............."+allowComment);
		if(allowComment.equals("yes"))
		{
			comment="T"	;
		}
		else
		{
			comment="F"	;
		}
		CategoryDAO categoryDao=new CategoryDAO();
		int rowAffected=categoryDao.update(id,name,comment);
		
		
		//categoryDao.closeConnection();
    	return mapping.findForward(SUCCESS);
		
	} 
}


